package com.xzx.study;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class SimpleComponentActivity extends AppCompatActivity {

    private ImageView image_view_simple_component;
    private CheckBox mCheckBox1;
    private CheckBox mCheckBox2;
    private CheckBox mCheckBox3;
    private Button mButton1;

    private RadioGroup mRadioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_component);

        image_view_simple_component = findViewById(R.id.image_view_simple_component);
        image_view_simple_component.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 设置背景图片
                image_view_simple_component.setBackgroundResource(android.R.drawable.alert_light_frame);
                // 设置前景图片
                image_view_simple_component.setImageResource(android.R.drawable.ic_media_pause);
            }
        });

        mCheckBox1 = findViewById(R.id.checkbox1);
        mCheckBox2 = findViewById(R.id.checkbox2);
        mCheckBox3 = findViewById(R.id.checkbox3);
        mButton1 = findViewById(R.id.button1);

        mCheckBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    Toast.makeText(SimpleComponentActivity.this, "足球选中", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(SimpleComponentActivity.this, "足球取消选中", Toast.LENGTH_SHORT).show();
                }
            }
        });
        mButton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StringBuilder builder = new StringBuilder();
                if (mCheckBox1.isChecked()) {
                    builder.append(mCheckBox1.getText().toString()).append(" ");
                }
                if (mCheckBox2.isChecked()) {
                    builder.append(mCheckBox2.getText().toString()).append(" ");
                }
                if (mCheckBox3.isChecked()) {
                    builder.append(mCheckBox3.getText().toString()).append(" ");
                }
                Toast.makeText(SimpleComponentActivity.this, builder.toString(), Toast.LENGTH_SHORT).show();
            }
        });

        mRadioGroup = findViewById(R.id.radioGroup);
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Toast.makeText(SimpleComponentActivity.this, radioButton.getText().toString(), 0).show();
            }
        });
    }
}
